 /**
  *@file    drvCD4052.c
  *@brief   CD4052 driver file
  *@author  zxf 2020-10-25
  *@version V1.0.0
  */
#include "board_pin.h"
#include "drvCD4052.h"

/* Private define ---------------------------------------*/


#define CD4052_A_LO()                  GPIO_Set_Lo(ENG_A_PORT, ENG_A_PIN)
#define CD4052_A_HI()                  GPIO_Set_Hi(ENG_A_PORT, ENG_A_PIN)

#define CD4052_B_LO()                  GPIO_Set_Lo(ENG_B_PORT, ENG_B_PIN)
#define CD4052_B_HI()                  GPIO_Set_Hi(ENG_B_PORT, ENG_B_PIN)

/* Private macro ----------------------------------------*/
/* Private typedef --------------------------------------*/
/* Private variables ------------------------------------*/
/* Private function prototypes --------------------------*/
/* Interface variables ----------------------------------*/

/* Interface functions ----------------------------------*/

void drvCD4052_Init(void)
{
    GPIO_InitType  GPIO_InitStructure;

    RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
    
    GPIO_InitStruct(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP;
    
    GPIO_InitStructure.Pin = ENG_A_PIN;
    GPIO_InitPeripheral(ENG_A_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = ENG_B_PIN;
    GPIO_InitPeripheral(ENG_B_PORT, &GPIO_InitStructure);
    
    drvCD4052_ChangeChn(MUX_CHN_NULL);
}

void drvCD4052_ChangeChn(u8 chn)
{
    switch(chn)
    {
    case CD4052_CHN_ID0:
        CD4052_A_LO();
        CD4052_B_LO();
        break;
    
    case CD4052_CHN_ID1:
        CD4052_A_HI();
        CD4052_B_LO();
        break;
    
    case CD4052_CHN_ID2:
        CD4052_A_LO();
        CD4052_B_HI();
        break;
    
    case CD4052_CHN_ID3:
        CD4052_A_HI();
        CD4052_B_HI();
        break;
    }
}

/* Private functions ------------------------------------*/

